package com.cj.cms.dao.security;

import java.util.Date;

import org.springframework.stereotype.Repository;

import com.cj.cms.entity.Template;
import com.cj.common.orm.hibernate.HibernateDao;
import com.cj.sys.service.ServiceException;

@Repository
public class TemplateDao extends HibernateDao<Template, Long> {
	@Override
	public void save(Template entity) {
		if(entity.getId() == null)
			entity.setCreateTime(new Date());
		if(entity.getType() == null)
			entity.setType(Template.CHANNEL_TEMPLATE);
		if(isPropertyUniqueById("code", entity.getCode(), entity.getId()))
			super.save(entity);
		else
			throw new ServiceException("模板代码已存在！" + entity.getCode());
	}
}
